package com.the4man.cnbdw.action;

import com.opensymphony.xwork2.ModelDriven;
import com.the4man.cnbdw.service.EmployeeBedService;
import com.the4man.cnbdw.utils.Page;
import com.the4man.framework.action.BaseAction;
import com.the4man.framework.model.DataGrid;
import com.the4man.framework.model.EmployeeBed;
import com.the4man.framework.model.EmployeeBedExample;
import com.the4man.framework.util.DateUtil;
import com.the4man.framework.util.LOG;
import com.the4man.framework.util.PageJson;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;

@Action(
        value = "employeeBedAction",
        results = {@Result(
                name = "addPage",
                location = "/cnbdw/employeeBed/add.jsp"
        ), @Result(
                name = "listPage",
                location = "/cnbdw/employeeBed/list.jsp"
        ), @Result(
                name = "editPage",
                location = "/cnbdw/employeeBed/edit.jsp"
        )}
)
public class EmployeeBedAction extends BaseAction implements ModelDriven<EmployeeBed> {
    private EmployeeBed employeeBed = new EmployeeBed();
    @Autowired
    private EmployeeBedService employeeBedService;

    public EmployeeBedAction() {
    }

    public String indexPage() {
        return "listPage";
    }

    public String toAddPage() {
        return "addPage";
    }

    public String toEditPage() {
        return "editPage";
    }

    public void getAllDatasourceList() {
        try {
            EmployeeBedExample employeeBedExample = new EmployeeBedExample();
            this.employeeBedService.countByExample(employeeBedExample);
            Page<EmployeeBed> page = new Page();
            this.setPageProperties(page);
            this.employeeBedService.selectByExample(employeeBedExample, page);
            DataGrid d = new DataGrid();
            d.setRows(page.getData());
            d.setTotal(Long.valueOf((long)page.getRowCount()));
            this.writeJson(d);
        } catch (Exception var5) {
            LOG.error("获取数据失败", var5, new String[0]);
        }

    }

    public void add() {
        PageJson json = new PageJson();

        try {
            String time = DateUtil.getInstance().formatDate(new Date());
            this.employeeBedService.insert(this.employeeBed);
            json.setReturnFlag(true);
            json.setReturnMsg("提交成功！");
        } catch (Exception var3) {
            json.setReturnFlag(false);
            json.setReturnMsg("提交出错了");
            LOG.error("获取数据失败", var3, new String[0]);
        }

        this.writeJson(json);
    }

    public void update() {
        PageJson json = new PageJson();

        try {
            this.employeeBedService.updateByPrimaryKey(this.employeeBed);
            json.setReturnFlag(true);
            json.setReturnMsg("提交成功！");
        } catch (Exception var3) {
            json.setReturnFlag(false);
            json.setReturnMsg("提交出错了");
            LOG.error("获取数据失败", var3, new String[0]);
        }

        this.writeJson(json);
    }

    public String executeModifyResult() {
        try {
            Object instance = this.employeeBedService.selectByPrimaryKey(this.employeeBed.getId(), EmployeeBed.class);
            this.getRequest().setAttribute("instance", instance);
        } catch (Exception var2) {
            LOG.error("获取数据失败", var2, new String[0]);
        }

        return "modifyPage";
    }

    public void delete() {
        PageJson json = new PageJson();

        try {
            int i = this.employeeBedService.deleteByPrimaryKey(this.getRequest().getParameter("ids"), EmployeeBed.class);
            if(i > 0) {
                json.setReturnMsg("删除EmployeeBed_info成功！");
                json.setReturnFlag(true);
            } else {
                json.setReturnMsg("删除EmployeeBed_info失败！");
                json.setReturnFlag(false);
            }
        } catch (Exception var3) {
            LOG.error("批量删除EmployeeBed_info失败！", var3, new String[0]);
            json.setReturnMsg("删除EmployeeBed_info失败！");
            json.setReturnFlag(false);
        }

        this.writeJson(json);
    }

    public void verify() {
        PageJson json = new PageJson();
        this.writeJson(json);
    }

    public EmployeeBed getModel() {
        return this.employeeBed;
    }
}
